<template>
  <!-- showProductPrice 是否展示价格 0-不展示 1-展示 -->
  <view>
    <view
      v-for="(item, index) in newOrderResData"
      :key="index"
      class="list-bg order-list-con"
      @click.stop="(item.orderStatus==10 || item.orderStatus==29 || item.auditStatus<10) ? '' : toOrderDetailFn(item.orderNo)"
    >
      <view v-if="item.orderStatus==10" class="tag">{{ item.settleType == 1201 ? '待确认' : '待付款' }}</view>
      <view v-else class="tag">{{ item.orderStatusName }}</view>
      <view class="company">{{ item.branchName }}</view>
      <view class="order-list-ul">
        <u-row>
          <u-col span="4">
            <view class="title">单据日期</view>
            <view class="info">{{ item.billDate }}</view>
          </u-col>
          <u-col v-if="false" span="4">
            <view class="title">下单账号</view>
            <view class="info">{{ item.xdAccount }}</view>
          </u-col>
          <u-col span="5">
            <view class="title">订单号</view>
            <view class="info">{{ item.orderNo }}</view>
          </u-col>
          <u-col span="3">
            <view class="title">发票状态</view>
            <view class="info">{{ item.invoiceStatusName }}</view>
          </u-col>
        </u-row>
      </view>
      <view class="order-all">共<text>{{ item.billCount }}</text>件商品&nbsp;&nbsp;&nbsp;&nbsp;实付：<text class="price">¥{{ item.showProductPrice && item.showProductPrice == 1 ? item.billAmount : '*.*' }}</text></view>
      <!--    1订单审核状态：已保存，非保存状态，不显示该按钮 auditStatus==0
                2订单主状态：待确认，非待确认的不显示订单确认按钮 orderStatus==10 ONLINE(1001, "在线支付"),ACCOUNT(1201,"账期支付"),COD(1101,"货到付款"),OFFLINE(1301,"线下汇款")
                3销售订单的下单账号：与当前登录账号一致，不一致的，不显示该按钮  xdAccount==vuex_accountInfo.loginAccount
                4销售订单的结算方式：为账期支付/在线支付，非账期支付的不显示该按钮  settleType==1201/1001
                5单据日期：等于系统当前日期或当前日期+1时展示，不满足条件时不显示该按钮 (billDate == curDate || billDate == curDate+1)
                6信用额度可用余额>=订单金额额度不足的，【订单确认】按钮置灰，并显示提醒【账期余额不足，请联系销售】  -->
      <button
        v-if="(item.auditStatus==0 && item.orderStatus==10 && item.xdAccount==vuex_accountInfo.loginAccount && item.settleType==1201 && (item.billDate == curDate || item.billDate == setFormatDate(curDate)))"
        class="btn-order"
        :type="'default'"
        plain="true"
        @click.stop="goPaymentFn(item.orderNo)"
      >去确认</button>
      <button
        v-if="(item.auditStatus==0 && (item.orderStatus==0 || item.orderStatus==10) && item.xdAccount==vuex_accountInfo.loginAccount && item.settleType==1001 && (item.billDate == curDate || item.billDate == setFormatDate(curDate)))"
        class="btn-order"
        :type="'default'"
        plain="true"
        @click.stop="goPaymentFn(item.orderNo)"
      >去支付</button>
      <button
        v-if="(item.orderType == 19654 || item.orderType == 19651 || item.orderType == 19655) && (item.orderStatus == 30 || item.orderStatus == 35)"
        class="btn-order"
        :type="'default'"
        plain="true"
        @click.stop="viewPickingInfoFn(item.orderNo)"
      >提货信息</button>
    </view>
  </view>
</template>

<script>
import { formatDate } from '@/common/common';
export default {
  name: 'OrderList',
  // 接受父组件的值
  props: {
    orderResData: {
      type: Array,
      default: null
    },
    /*botLoadingShow: {
      type: Number,
      default: 0
    },*/
    date: {
      type: String,
      default: ''
    },
    /*creditLines: {
      type: Number,
      default: 0
    }*/
  },
  data() {
    return {
      newOrderResData: this.orderResData
    }
  },
  computed: {
    curDate() {
      return this.date
    },
    /*curCreditLines() {
      return this.creditLines
    }*/
  },
  watch: {
    orderResData(newVal) {
      this.newOrderResData = newVal
      console.log(this.newOrderResData)
    }
  },
  methods: {
    setFormatDate(time) {
      const orderNextTime = formatDate(new Date(new Date(time).getTime() + (24 * 60 * 60 * 1000)), 'yyyy-mm-dd')
      return orderNextTime
    },
    /*查看订单详情*/
    toOrderDetailFn(orderNo) {
      uni.navigateTo({
        url: '/orders/order-details/order-details?orderNo=' + orderNo
      });
    },
    /*查看提货信息*/
    viewPickingInfoFn(orderNo) {
      uni.navigateTo({
        url: '/orders/pickup-Infomation/pickup-Infomation?orderNo=' + orderNo
      });
    },
    /*跳转订单确认页*/
    goPaymentFn(orderNo) {
      uni.navigateTo({
        url: '/payments/payment/payment?orderNo=' + orderNo + '&pageSource=local'
      });
    }
  }
}
</script>

<style scoped lang="scss">
.list-bg {
  margin: 0;
  margin-top: 20rpx;
}
.order-list-con{
  position: relative;
  .company{
    padding:20rpx 0 0 64rpx;
    background:url("../../static/image/shop-gray.png") no-repeat 24rpx 22rpx/28rpx 26rpx;
  }
  .tag{
    position: absolute;
    color:$uni-orange;
    right:36rpx;
    top:22rpx;
  }
  .order-list-ul{
    padding: 38rpx 0 24rpx;
    .title{
      padding:0 24rpx;
      color:$uni-grey-999;
      font-size:$uni-font-size-sm;
      line-height:30rpx;
    }
    .info{
      padding:8rpx 24rpx 0;
      height: 42rpx;
      line-height: 42rpx;
      font-size: $uni-font-size-lg;
      font-weight: bold;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .order-all{
    height: 84rpx;
    line-height: 84rpx;
    color:$uni-grey-999;
    padding: 0 24rpx;
    .price{
      font-size:$uni-font-size-base;
      color:$uni-orange;
      font-weight: bold;
    }
  }
  .btn-order,.btn-order:active{
    position: absolute;
    bottom:18rpx;
    right:30rpx;
    padding:0 20rpx;
    height: 60rpx;
    line-height: 58rpx;
    font-size:$uni-font-size-sm;
    color:$uni-white;
    border-color:$uni-orange;
    border-radius:34rpx;
    background:$uni-orange;
  }
  .disabled-btn{
    background: $uni-text-color-disable;
  }
}
</style>
